﻿using System;
using System.Collections.Generic;
using Medianamik.Core.DAL;
using Medianamik.Core.DAL.Repositories;
using Medianamik.Core.DAL.Services;
using Medianamik.Core.Redirect;
using System.Linq;

namespace Medianamik.Client.Data.Repositories
{
    public interface IExternalRedirectRepository : IMedianamikRepository<MedianamikExternalRedirect>
    {

    }

    public class ExternalRedirectRepository : MedianamikRepository<MedianamikExternalRedirectCollection,
            MedianamikExternalRedirect>, IExternalRedirectRepository, IExternalRedirectUrlRepository
    {
        public ExternalRedirectRepository(ICultureService cultureService,
            IContentStateService contentStateService, INodeMapper nodeMapper)
            : base(cultureService, contentStateService, nodeMapper)
        {
        }

        public IList<ExternalRedirect> GetAllExternalRedirect()
        {
            return AllInstances().Select(r =>
                new ExternalRedirect(r.RedirectFrom, r.RedirectTo, r.RedirectCode.GetValueOrDefault(301))).ToList();
        }
    }
}
